import {Button, Divider, Input, Layout, Menu} from 'antd';
import {useEffect, useState} from "react";
import {useNavigate} from "react-router-dom";
import './Publish.css';
import axios from "axios";



// 发布组件
export default function Publish() {
    const [title, setTitle] = useState('');  // 标题
    const [content, setContent] = useState('');  // 内容
    const navigate = useNavigate();


    function onPublish() {
        let local_data = localStorage.getItem('userData');
        let now_user = JSON.parse(local_data)['user'];   // 获取当前用户信息
        let data = {
            title: title,
            content: content,
            user: now_user,
        };

        axios.post('/api/card', data)
            .then((res) => {
                navigate('/home/user');
            })
    }


    function handleChangeContent(e) {
        setContent(e.target.value);
        console.log(e.target.value);
    }

    return (
        <Layout>
            <from className="card">
                <div className="card-body">
                    <div className="card-title-province">
                        <Input placeholder="标题" onChange={(e) => setTitle(e.target.value)}/>
                    </div>
                    <Divider dashed/>
                    <div className="card-content">
                        <Input.TextArea placeholder="灵感内容" onChange={handleChangeContent}/>
                    </div>
                    <Divider dashed/>
                    <Button onClick={onPublish}>发 布</Button>
                </div>
            </from>
        </Layout>
)
}